package com.xudow.app.dynamicstate_old.module.discovery.viewholder;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.xudow.app.R;
import com.xudow.app.dynamicstate_old.domain.entity.Dynamic;
import com.xudow.app.dynamicstate_old.widget.exview.ExGridView;
import com.xudow.app.dynamicstate_old.widget.exview.NetImageAdapter;

import butterknife.BindView;

/**
 * Created by ske on 2016/5/22.
 */
public class PostNormalViewHolder extends DynamicContentViewHolder {
    @BindView(R.id.dynamic_follows_content_normal)
    TextView normalPostContent;
    @BindView(R.id.dynamic_follows_content_normal_img)
    ExGridView normalPostImg;
    NetImageAdapter imageAdapter;

    public PostNormalViewHolder(RecyclerArrayAdapter<Dynamic> adapter, ViewGroup parent) {
        super(adapter, parent, R.layout.discover_item_post_normal);
        normalPostImg.setAdapter(imageAdapter = new NetImageAdapter(parent.getContext()));
        adapter.setNotifyOnChange(false);
    }

    @Override
    public void setData(Dynamic dynamic) {
        super.setData(dynamic);
        // 设置content
        normalPostContent.setText(dynamic.getContent());
        //图片
        imageAdapter.clear();
        if (!TextUtils.isEmpty(dynamic.getImgpath())) {
            normalPostImg.setVisibility(View.VISIBLE);
            String[] paths = dynamic.getImgpath().split(";");
            normalPostImg.setColumnCount(paths.length == 1 ? 2 : 3);
            imageAdapter.addAll(paths);
            imageAdapter.notifyDataSetChanged();
        } else {
            normalPostImg.setVisibility(View.GONE);
        }
    }
}
